// pages/myPages/personalCenter/ReceivablesInformation/createReceipt/createReceipt.js
var request = require('./request.js')

//获取应用实例
const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    showView: false,
    majorMain:'',
    alipayList:[],
    alipayMethod:[],
    setLang:{}
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this;
  },
  getList: function (e) {
    var that = this;
    var data = {
      access_token: wx.getStorageSync('createUser').access_token
    };
    request.getList(data, function (d) {
      console.log(d)
      
      if(d.data != null){
        if (d.code == 200) {
          that.setData({
            majorMain: 1,
            alipayList: d.data
          })
        }
      }else{
        that.setData({
          majorMain: ''
        })
      }
    });
  },
  getMethod: function (e) {
    var that = this;
    var data = {
      access_token: wx.getStorageSync('createUser').access_token
    };
    request.getMethod(data, function (d) {
      console.log(d)
      if (d.code == 200) {
        that.setData({
          alipayMethod:d.data
        })
      }
    });
  },
  onChangeShowState: function (e) {
    var that = this;
    var current = e.currentTarget.dataset.current;
    var proceeds_type = e.currentTarget.dataset.proceeds_type;
    that.setData({
      showView: (!that.data.showView)
    })
    if (proceeds_type == 'alipay'){
      wx.navigateTo({
        url: './createAAlipay/createAAlipay?proceeds_type=' + proceeds_type +''
      })
    } else if (proceeds_type == 'bank'){
      wx.navigateTo({
        url: './createABankCard/createABankCard?proceeds_type=' + proceeds_type +''
      })
    } else if (proceeds_type == 'wxpay'){
      wx.navigateTo({
        url: './createWeChat/createWeChat?proceeds_type=' + proceeds_type +''
      })
    }
  },
  infoDetail:function(e){
    var current = e.currentTarget.dataset.current;
    var index = e.currentTarget.dataset.index;
    var id = this.data.alipayList[index].id;
    // var username = e.currentTarget.dataset.username;
    // var qrcode = e.currentTarget.dataset.qrcode;
  
    if (current == 1){
      wx.navigateTo({
        url: './infoDetail/infoDetail?id=' + id + ''
      })
    } else if (current == 0){
      wx.navigateTo({
        url: './BankInfoDetail/BankInfoDetail?id=' + id + ''
      })
    }
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    
    var that = this;
    this.setData({
      setLang: wx.T.locale == "zh-Hans" ? wx.T.locales['zh-Hans'] : wx.T.locales['en']

    })
    wx.setNavigationBarTitle({
      title: wx.T.locale == "zh-Hans" ? wx.T.locales['zh-Hans'].BankCardManagement : wx.T.locales['en'].BankCardManagement
    })
    that.getList();
    that.getMethod();
  },
  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  
  },
  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  
  },
  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
  
  },
  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
  
  },
  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
  
  }
})